home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / utils1 / gentree.zip / POLYMRPH.CPP < prev    next >
C/C++ Source or Header  |  1994-05-26  |  3KB  |  113 lines

  1. // POLYMRPH.CPP - Is an example of how you can use the GENTREE program
  2. // to build you own custom applications.
  3. // Copyright (c) Paul Kimmel 1994
  4. // All Rights Reserved
  5.  
  6. /***********************************************************************
  7.  GENTREE - Lets you design your own customized OS commands.  GENTREE simply
  8.  traverses a DOS tree given a starting path and the res is up to you.
  9.  Have you ever wanted to delete all *.BAK files on a disk? Well with
  10.  GENTREE you can run. For example, executing GENTREE with the following
  11.  arguments: GENTREE C: DEL *.BAK will search the entire disk executing
  12.  the program DEL with arguments *.BAK. Simply follow the syntax required
  13.  by GENTREE and it will do whatever you want it to.
  14.  
  15.  SYNTAX: gentree path prog_name arg1,arg2,arg3...
  16.  Where path is any starting DOS path (e.g. C:, C:\DOS, D:\DOC)
  17.  Where prog_name is any non-TSR executable, command, or batch program
  18.  Where arg1,arg2 etc... are arguments you want that program (progr_name)
  19.     to use as its arguments.
  20.  
  21.  The second way to use GENTREE is with the source code. The sample executable
  22.  program bundled with GENTREE does what is mentioned above. But provide
  23.  GENTREE with your own function and it becomes something completely new.
  24.  
  25.  Just follow the example in the source code adding your function argument
  26.  and compile and link.
  27.  
  28.  GENTREE is available in PASCAL for 19.95 + shipping and handling.
  29.  *************************************************************************/
  30.  
  31. #include "gentree.h"
  32.  
  33. #include <dos.h>
  34. #include <dir.h>
  35. #include <process.h>
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <mem.h>
  40.  
  41.  
  42. const int MAX_COMMAND_LEN = 129;    // dos limitation!
  43. char command[ MAX_COMMAND_LEN ];
  44.  
  45. char pathName[ MAX_COMMAND_LEN ];
  46.  
  47.  
  48. // The function gentree calls
  49. void PolyMorph()
  50. {
  51.     system( command );
  52. }
  53.  
  54. void NormalizePathName( char* pname )
  55. {
  56.     int j=0;
  57.  
  58.     for( int i=0; i<strlen( pname ); i++ ){
  59.  
  60.         if( pname[i] == '\\' ){
  61.             pathName[j++] = '\\';
  62.         }
  63.         pathName[ j++ ] = pname[i];
  64.     }
  65. }
  66.  
  67.  
  68. // Build the commands for the PolyMorph function
  69. void BuildCommand( int count, char* args[] )
  70. {
  71.  
  72.     memset( command, (int) 'P', MAX_COMMAND_LEN);
  73.     command[ MAX_COMMAND_LEN - 1] = '\0';
  74.  
  75.     if ( count >= 2 ){
  76.         strcpy( command, args[2] );
  77.         strcat( command, " ");
  78.  
  79.  
  80.         for( int i=3; i<count; i++ ){
  81.             strcat( command, args[i] );
  82.             strcat( command, " ");
  83.         }
  84.     }
  85. }
  86.  
  87.  
  88.  
  89. // sample usage of the gentree functions
  90.  
  91. void main( int argc, char* argv[] )
  92. {
  93.     struct ffblk ffblk;
  94.  
  95.     if( argc < 2 ){
  96.         printf( "syntax: gentree [drive:\][dir] prog_name args,...\n" );
  97.         return;
  98.     }
  99.  
  100.    NormalizePathName( argv[1] );
  101.  
  102.    if( !findfirst( pathName, &ffblk, FA_DIREC )) {
  103.         printf( "starting directory %s not found\n", argv[1] );
  104.         return;
  105.    }
  106.  
  107.    BuildCommand( argc, argv );
  108.  
  109.    printf ("entered: %s \n", command );
  110.  
  111.    GenTree( PolyMorph, argv[1] );
  112. }
  113.